
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.ExceptionType;
import cn.edu.scau.cmi.hombio.domain.Inspection;
import cn.edu.scau.cmi.hombio.domain.InspectionException;
import cn.edu.scau.cmi.hombio.domain.Pigsty;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class InspectionExceptionServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected InspectionExceptionService service;

	/**
	 * Instantiates a new InspectionExceptionServiceTest.
	 *
	 */
	public InspectionExceptionServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findInspectionExceptionByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findInspectionExceptionByPrimaryKey 
		Integer id = 0;
		InspectionException response = null;
		response = service.findInspectionExceptionByPrimaryKey(id);
		// TODO: JUnit - Add assertions to test outputs of operation: findInspectionExceptionByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Delete an existing ExceptionType entity
	* 
	 */
	@Test
	public void deleteInspectionExceptionExceptionType() {
		// TODO: JUnit - Populate test inputs for operation: deleteInspectionExceptionExceptionType 
		Integer inspectionexception_id = 0;
		Integer related_exceptiontype_id = 0;
		InspectionException response = null;
		response = service.deleteInspectionExceptionExceptionType(inspectionexception_id, related_exceptiontype_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteInspectionExceptionExceptionType
	}

	/**
	 * Operation Unit Test
	* Save an existing Inspection entity
	* 
	 */
	@Test
	public void saveInspectionExceptionInspection() {
		// TODO: JUnit - Populate test inputs for operation: saveInspectionExceptionInspection 
		Integer id_1 = 0;
		Inspection related_inspection = new cn.edu.scau.cmi.hombio.domain.Inspection();
		InspectionException response = null;
		response = service.saveInspectionExceptionInspection(id_1, related_inspection);
		// TODO: JUnit - Add assertions to test outputs of operation: saveInspectionExceptionInspection
	}

	/**
	 * Operation Unit Test
	* Save an existing ExceptionType entity
	* 
	 */
	@Test
	public void saveInspectionExceptionExceptionType() {
		// TODO: JUnit - Populate test inputs for operation: saveInspectionExceptionExceptionType 
		Integer id_2 = 0;
		ExceptionType related_exceptiontype = new cn.edu.scau.cmi.hombio.domain.ExceptionType();
		InspectionException response = null;
		response = service.saveInspectionExceptionExceptionType(id_2, related_exceptiontype);
		// TODO: JUnit - Add assertions to test outputs of operation: saveInspectionExceptionExceptionType
	}

	/**
	 * Operation Unit Test
	* Delete an existing Pigsty entity
	* 
	 */
	@Test
	public void deleteInspectionExceptionPigsty() {
		// TODO: JUnit - Populate test inputs for operation: deleteInspectionExceptionPigsty 
		Integer inspectionexception_id_1 = 0;
		Integer related_pigsty_id = 0;
		InspectionException response = null;
		response = service.deleteInspectionExceptionPigsty(inspectionexception_id_1, related_pigsty_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteInspectionExceptionPigsty
	}

	/**
	 * Operation Unit Test
	* Save an existing Pigsty entity
	* 
	 */
	@Test
	public void saveInspectionExceptionPigsty() {
		// TODO: JUnit - Populate test inputs for operation: saveInspectionExceptionPigsty 
		Integer id_3 = 0;
		Pigsty related_pigsty = new cn.edu.scau.cmi.hombio.domain.Pigsty();
		InspectionException response = null;
		response = service.saveInspectionExceptionPigsty(id_3, related_pigsty);
		// TODO: JUnit - Add assertions to test outputs of operation: saveInspectionExceptionPigsty
	}

	/**
	 * Operation Unit Test
	* Load an existing InspectionException entity
	* 
	 */
	@Test
	public void loadInspectionExceptions() {
		Set<InspectionException> response = null;
		response = service.loadInspectionExceptions();
		// TODO: JUnit - Add assertions to test outputs of operation: loadInspectionExceptions
	}

	/**
	 * Operation Unit Test
	* Delete an existing InspectionException entity
	* 
	 */
	@Test
	public void deleteInspectionException() {
		// TODO: JUnit - Populate test inputs for operation: deleteInspectionException 
		InspectionException inspectionexception = new cn.edu.scau.cmi.hombio.domain.InspectionException();
		service.deleteInspectionException(inspectionexception);
	}

	/**
	 * Operation Unit Test
	* Delete an existing Inspection entity
	* 
	 */
	@Test
	public void deleteInspectionExceptionInspection() {
		// TODO: JUnit - Populate test inputs for operation: deleteInspectionExceptionInspection 
		Integer inspectionexception_id_2 = 0;
		Integer related_inspection_id = 0;
		InspectionException response = null;
		response = service.deleteInspectionExceptionInspection(inspectionexception_id_2, related_inspection_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteInspectionExceptionInspection
	}

	/**
	 * Operation Unit Test
	* Return a count of all InspectionException entity
	* 
	 */
	@Test
	public void countInspectionExceptions() {
		Integer response = null;
		response = service.countInspectionExceptions();
		// TODO: JUnit - Add assertions to test outputs of operation: countInspectionExceptions
	}

	/**
	 * Operation Unit Test
	* Return all InspectionException entity
	* 
	 */
	@Test
	public void findAllInspectionExceptions() {
		// TODO: JUnit - Populate test inputs for operation: findAllInspectionExceptions 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<InspectionException> response = null;
		response = service.findAllInspectionExceptions(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllInspectionExceptions
	}

	/**
	 * Operation Unit Test
	* Save an existing InspectionException entity
	* 
	 */
	@Test
	public void saveInspectionException() {
		// TODO: JUnit - Populate test inputs for operation: saveInspectionException 
		InspectionException inspectionexception_1 = new cn.edu.scau.cmi.hombio.domain.InspectionException();
		service.saveInspectionException(inspectionexception_1);
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
